home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / HyperCard Dev. ToolKit / Serial & MacinTalk XCMDs / speak.p < prev    next >
Text File  |  1987-07-15  |  2KB  |  95 lines

  1. {$R-}
  2.  
  3. (*
  4.     speak string[,phonemes?] -- Speak the string, either as text or as phonemes. If the last parameter is present,
  5.         use phonemes, otherwise translate the text in string into phonemes first.
  6.  
  7.     To compile and link this file using Macintosh Programmer's Workshop,
  8.  
  9.     pascal -w speak.p
  10.     link -m ENTRYPOINT -o WildSpeak -rt XCMD=0 -sn Main=speak speak.p.o SpeechIntf.o "{MPW}"Libraries:interface.o
  11.     
  12. *)
  13.  
  14. {$S speak }     { Segment name must be the same as the command name. }
  15.  
  16. unit DummyUnit;
  17.  
  18. interface
  19.  
  20. uses MemTypes, QuickDraw, OSIntf, HyperXCmd, SpeechIntf;
  21.  
  22. procedure EntryPoint(paramPtr: XCmdPtr);
  23.     
  24. implementation
  25.  
  26. type
  27.  
  28. Str31 = String[31];
  29.  
  30. procedure speak(paramPtr: XCmdPtr); forward;
  31.  
  32. procedure EntryPoint(paramPtr: XCmdPtr);
  33.  
  34.     begin
  35.         speak(paramPtr);
  36.     end;
  37.  
  38. procedure speak(paramPtr: XCmdPtr);
  39.  
  40.     var portNumber: integer;
  41.         setting: integer;
  42.         inPort, outPort: integer;
  43.         str: Str255;
  44.  
  45.     {$I XCmdGlue.inc}
  46.  
  47.     procedure Fail(errMsg: Str255); { set theResult and quit }
  48.         begin
  49.             paramPtr^.returnValue := PasToZero(errMsg);
  50.             exit(speak);
  51.         end;
  52.  
  53.  
  54. var
  55.  
  56. SpeakHandle: SpeechHandle;
  57. usePhonemes: boolean;
  58. dummy: integer;
  59. theSpeech: Handle;
  60.  
  61. begin
  62.     if (paramPtr^.paramCount <> 1) and (paramPtr^.paramCount <> 2) then Fail('wrong number of parameters');
  63.     usePhonemes := paramPtr^.paramCount = 2;
  64.  
  65.     if SpeechOn('',SpeakHandle) = noErr then
  66.         begin
  67.             if GetHandleSize(paramPtr^.params[1]) > 1 then
  68.                 begin
  69.                     if usePhonemes then
  70.                         begin
  71.                             theSpeech := paramPtr^.params[1];
  72.                             if HandToHand(theSpeech) = noErr then
  73.                                 begin
  74.                                     SetHandleSize(theSpeech,GetHandleSize(theSpeech)-1);
  75.                                     dummy := MacinTalk(SpeakHandle,paramPtr^.params[1]);
  76.                                     DisposHandle(theSpeech);
  77.                                 end;
  78.                         end
  79.                     else
  80.                         begin
  81.                             theSpeech := NewHandle(0);
  82.                             HLock(paramPtr^.params[1]);
  83.                             if Reader(SpeakHandle,paramPtr^.params[1]^,GetHandleSize(paramPtr^.params[1])-1,theSpeech) = noErr then
  84.                                 dummy := MacinTalk(SpeakHandle,theSpeech);
  85.                             HUnlock(paramPtr^.params[1]);
  86.                             DisposHandle(theSpeech);
  87.                         end;
  88.                 end;
  89.             SpeechOff(SpeakHandle);
  90.         end
  91.     else Fail('SpeechOn failed');
  92. end;
  93.  
  94. end.
  95.